Repository navigation
fix: prevent prototype pollution via inherited parse results - #184
Merged
Merged
Conversation
mri read previously parsed flags from a plain object without an own-property check, so a `--__proto__` flag replaced the prototype of its result and later flags could hand `Object.prototype` back to cac as an option value. Walking a dotted option name into that value then wrote onto `Object.prototype`, which the existing `UNSAFE_KEYS` check on key names does not catch. mri is no longer maintained, so it is now forked into `src/mri.ts`, trimmed to the options cac uses. Its result object has no prototype, so flags such as `--__proto__` or `--toString` are plain own keys. Parsing is otherwise unchanged, checked against mri 1.2.0 on randomly generated argv. mri's MIT notice is added to LICENSE. `setDotProp()` also stops descending into inherited members, so `--valueOf.x=1` no longer writes onto the built-in `Object.prototype.valueOf`. Reported-by: João Pereira <joaomhmpereira@gmail.com>
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #184 +/- ##
==========================================
+ Coverage 67.01% 69.12% +2.11%
==========================================
Files 6 7 +1
Lines 388 447 +59
Branches 106 127 +21
==========================================
+ Hits 260 309 +49
- Misses 111 118 +7
- Partials 17 20 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sxzz
approved these changes
Nov 20, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mri read previously parsed flags from a plain object without an own-property check. A
--__proto__flag replaced the prototype of its result, so later flags could passObject.prototypeback to cac as an option value. Walking a dotted option name into that value then wrote ontoObject.prototype. The existingUNSAFE_KEYScheck only looks at key names, so it did not catch this.Changes
src/mri.ts. mri has not had a release since 2021, so it is now part of cac, trimmed to the options cac uses (alias,boolean). Its result object has no prototype, so flags such as--__proto__or--toStringare plain own keys. ThemridevDependency, theinlineDepssetup and theinlinedDependenciesfield are removed.setDotProp(). It no longer descends into inherited members, so--valueOf.x=1does not write onto the built-inObject.prototype.valueOf.LICENSE.Verification
ignore inherited members while parsing options. It fails without this change.src/mri.tswas compared with mri 1.2.0 on 300k randomly generated argv and alias/boolean configs. Outputs and thrown errors were identical.pnpm test,pnpm lint,pnpm typecheckandpnpm buildpass.Reported by João Pereira.